
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Xml;
using Swaf.Call;
using Swaf.Container;

namespace Swaf.Security
{
	/// <summary>
	/// The SessionSecurityManager is a specialized implementation of the ISecurityManager 
	/// interface geared specifically to the lightweight SessionApplication objects.  This 
	/// security manager implementation contains its own ISecurityPrincipal instance and 
	/// otherwise, simply passes through to the global security manager instance on the 
	/// Application object.
	/// </summary>
	public class SessionSecurityManager : MarshalByRefObject,ISecurityManager
	{
		protected ISecurityManager m_globalSecurityManager=null;
		protected ISecurityPrincipal m_sessionPrincipal=null;

		/// <summary>
		/// Default constructor for class
		/// </summary>
		public SessionSecurityManager()
		{
			m_globalSecurityManager = Application.globalApp.securityMgr;
		}
		#region ISecurityManager Members

		/// <summary>
		/// Returns the session level current security principal
		/// </summary>
		public ISecurityPrincipal currentPrincipal
		{
			get
			{
				return m_sessionPrincipal;
			}
			set
			{
				m_sessionPrincipal = value;
			}
		}

		/// <summary>
		/// <see cref="ISecurityManager.resourceSets"/>
		/// </summary>
		public Swaf.Container.INameAddressSupport resourceSets
		{
			get
			{
				return m_globalSecurityManager.resourceSets;
			}
		}

		/// <summary>
		/// <see cref="ISecurityManager.createPrincipal"/>
		/// </summary>
		/// <param name="UserName"></param>
		/// <param name="additionalInfo"></param>
		/// <param name="rolesCall"></param>
		/// <returns></returns>
		public ISecurityPrincipal createPrincipal(string UserName, INameAddressSupport additionalInfo, ICall rolesCall)
		{
			return m_globalSecurityManager.createPrincipal(UserName, additionalInfo, rolesCall);
		}	
		/// <summary>
		/// <see cref="ISecurityManager.createPrincipal"/>
		/// </summary>
		/// <param name="principalInfo"></param>
		/// <returns></returns>
		public ISecurityPrincipal createPrincipal(Swaf.Container.INameAddressSupport principalInfo)
		{
			return m_globalSecurityManager.createPrincipal(principalInfo);
		}
		/// <summary>
		/// <see cref="ISecurityManager.createPrincipal"/>
		/// </summary>
		public ISecurityPrincipal createPrincipal(XmlElement principalEle)
		{
			return m_globalSecurityManager.createPrincipal(principalEle);
		}
		public ICall defaultRolesCall
		{
			get{return m_globalSecurityManager.defaultRolesCall;}
		}
		public void setCurrentPrincipal(string UserName, INameAddressSupport additionalInfo, string instanceId)
		{
			m_sessionPrincipal=createPrincipal(UserName,additionalInfo,m_globalSecurityManager.defaultRolesCall);
			((SecurityPrincipalBase) m_sessionPrincipal).m_instanceId=instanceId;
		}

		#endregion

	}
}
